//
//  HMHeaderView.m
//  G05爱鲜蜂
//
//  Created by 小灰灰 on 16/10/19.
//  Copyright © 2016年 何源. All rights reserved.
//

#import "HMHeaderView.h"
#import "HMHelpModel.h"
@interface HMHeaderView()
@end
@implementation HMHeaderView

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithReuseIdentifier:reuseIdentifier]){
      
         [self creatSubView];
    }
    return self;
}
-(void)creatSubView{
 
    UIButton *inv = [[UIButton alloc] init];
    [inv setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    inv.titleLabel.font = [UIFont systemFontOfSize:16];
     [inv setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    inv.titleLabel.textColor = [UIColor blackColor];
    inv.imageEdgeInsets = UIEdgeInsetsMake(0,[UIScreen mainScreen].bounds.size.width - 30, 0, 0);
    [inv addTarget:self action:@selector(btnDIdClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:inv];
    _invBtn = inv;
}

-(void)setModel:(HMHelpModel *)model{
    //设置数据
    _model = model;
    
    [self.invBtn setTitle:model.title forState:UIControlStateNormal];
    [self.invBtn setImage:[UIImage imageNamed:@"cell_arrow_down_accessory"] forState:UIControlStateNormal];

    if(self.model.open){
        self.invBtn.selected = YES;
        [self.invBtn setImage:[UIImage imageNamed:@"cell_arrow_up_accessory"] forState:UIControlStateNormal];
    }else{
        self.invBtn.selected = NO;
        [self.invBtn setImage:[UIImage imageNamed:@"cell_arrow_down_accessory"] forState:UIControlStateNormal];
    }

}
-(void)btnDIdClick:(UIButton *)btn{
    if([self.delegate respondsToSelector:@selector(btnDidClickHeaderView:)])
    {
        [self.delegate btnDidClickHeaderView:self];
    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
    self.invBtn.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
 }
@end
